/*************************************************************************
 *                                                                       *
 * This file is part of the DogosFrame distribution.  For full copyright *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 *                                                                       *
 *************************************************************************/

//declaration header
#include "COMMON/math/TypeVector.h"

// C++ includes
#include <iostream>
#include <iomanip> // for std::setw, std::setiosflags

namespace DOGOS
{

template <typename T>
TypeVector<T> TypeVector<T>::unit() const
{

    const double length = norm();

    TBOX_ASSERT_NE (length, static_cast<double>(0.));

    return TypeVector<T>(_coords[0]/length,
                         _coords[1]/length,
                         _coords[2]/length);
}



template <typename T>
void TypeVector<T>::print(std::ostream & os) const
{
    os <<  "(x,y,z)=("
       << std::setw(8) << (*this)(0) << ", "
       << std::setw(8) << (*this)(1) << ", "
       << std::setw(8) << (*this)(2) << ")";
}





template <typename T>
void TypeVector<T>::write_unformatted (std::ostream & os,
                                       const bool newline) const
{
    TBOX_ASSERT (os);

    os << std::setiosflags(std::ios::showpoint)
       << (*this)(0) << " "
       << (*this)(1) << " "
       << (*this)(2) << " ";

    if (newline)
        os << '\n';
}



template <typename T>
bool TypeVector<T>::operator < (const TypeVector<T> & rhs) const
{
    for (unsigned int i=0; i<3; i++)
    {
        if ((*this)(i) < rhs(i))
            return true;
        if ((*this)(i) > rhs(i))
            return false;
    }
    return false;
}


template <typename T>
bool TypeVector<T>::operator <= (const TypeVector<T> & rhs) const
{
    for (unsigned int i=0; i<3; i++)
    {
        if ((*this)(i) < rhs(i))
            return true;
        if ((*this)(i) > rhs(i))
            return false;
    }
    return true;
}



template <typename T>
bool TypeVector<T>::operator > (const TypeVector<T> & rhs) const
{
    for (unsigned int i=0; i<3; i++)
    {
        if ((*this)(i) > rhs(i))
            return true;
        if ((*this)(i) < rhs(i))
            return false;
    }
    return false;
}


template <typename T>
bool TypeVector<T>::operator >= (const TypeVector<T> & rhs) const
{
    for (unsigned int i=0; i<3; i++)
    {
        if ((*this)(i) > rhs(i))
            return true;
        if ((*this)(i) < rhs(i))
            return false;
    }
    return true;
}



// ------------------------------------------------------------
// Explicit instantiations
template class TypeVector<double>;

}
